/**
 * 用户主页需要调用的js文件
 */

layui.use([ 'layer' ], function() {
	var layer = layui.layer;
	/****删除发布文章*****/
	$("span#essaydelete").click(function(){
		var essayId=$(this).attr("essayId");
		layer.confirm('确认删除吗?', {icon: 2, title:'小贴士'}, function(index){
			$.ajax({
				type : 'POST',
				url : '/essay/deleteessay.do',
				data : {
					essayId:essayId
				},
				success : function(resl) {
					if (resl == "success") {
						 layer.msg("删除成功",{icon:1,time:500},function() {
							 window.location.href="/essay/essayreadbyuser.do";
	                        });
						
					} else if(resl=="false"){
						layer.alert('好像没有删除成功哦', function(index){
							  location.reload();
							  layer.close(index);
							  return false;
							}); 
					}
				}
			});
			  layer.close(index);
			});
	});
	/************取消收藏文章**********/
	$(document).ready(function(){  
		$("#uncollection").click(function(){
			var essayId = $(this).attr("essayId");
			$.ajax({
				type:'POST',
				url:'/collection/canclecollect.do',
				data:{
					essayId:essayId,
				},
				success:function(value){
					if(value=="success"){
						 layer.msg("取消收藏成功",{icon:1,time:500},function() {
							 window.location.href="/essay/essayreadbyuser.do";
	                        });
					}else if(value=="false"){
						layer.msg("服务器好像出错了，请稍后再试");
					}
				}
			});
		});
	});
	/*******************************/
	$("span#uncollection").click(function(){
		var userId=$(this).attr("userId");
		layer.confirm('确认取消关注吗?', {icon: 2, title:'小贴士'}, function(index){
			$.ajax({
				type : 'POST',
				url : '/attention/unattention.do',
				data : {
					userId:userId
				},
				success : function(resl) {
					if (resl == "success") {
						 layer.msg("取消关注成功",{icon:1,time:500	},function() {
							 window.location.href="/essay/essayreadbyuser.do";
	                        });
						
					} else if(resl=="false"){
						layer.alert('好像没有操作i成功哦', function(index){
							  location.reload();
							  layer.close(index);
							  return false;
							}); 
					}
				}
			});
			  layer.close(index);
			});
	});

	/*************************************分页（刷新分页实例）*******************************************/

	layui.use('laypage', function () {
		var laypage = layui.laypage;
		var totalCount=$("#PublishNumber").val();
		var whichPage=$("#whichPage").val();
		var currentPage=$("#PcurrentPage").val();
		//执行一个laypage实例
		laypage.render({
			elem: 'Bpage'
			, count: totalCount
			, limit: 10
			, curr: currentPage //获取起始页
			, first: '首页'
			, last: '尾页'
			, prev: '<em>←</em>'
			, next: '<em>→</em>'
			, skip: true
			, jump: function (obj, first) {
				if (!first) {
					window.location.href="/essay/essayreadbyuser.do?PcurrentPage="+obj.curr+"&whichPage="+whichPage;
				}
			}
		});
	});

	layui.use('laypage', function () {
		var laypage = layui.laypage;
		var totalCount=$("#CollectionNumber").val();
		var whichPage=$("#whichPage").val();
		var userId=$("#userId").val();
		var currentPage=$("#CcurrentPage").val();
		//执行一个laypage实例
		laypage.render({
			elem: 'Bpage1'
			, count: totalCount
			, limit: 20
			, curr: currentPage //获取起始页
			, first: '首页'
			, last: '尾页'
			, prev: '<em>←</em>'
			, next: '<em>→</em>'
			, skip: true
			, jump: function (obj, first) {
				if (!first) {
					window.location.href="/essay/essayreadbyuser.do?CcurrentPage="+obj.curr+"&whichPage="+whichPage;
				}
			}
		});
	});

	layui.use('laypage', function () {
		var laypage = layui.laypage;
		var totalCount=$("#AttentionNumber").val();
		var whichPage=$("#whichPage").val();
		var currentPage=$("#AcurrentPage").val();
		//执行一个laypage实例
		laypage.render({
			elem: 'Bpage2'
			, count: totalCount
			, limit: 20
			, curr: currentPage //获取起始页
			, first: '首页'
			, last: '尾页'
			, prev: '<em>←</em>'
			, next: '<em>→</em>'
			, skip: true
			, jump: function (obj, first) {
				if (!first) {
					window.location.href="/essay/essayreadbyuser.do?AcurrentPage="+obj.curr+"&whichPage="+whichPage;
				}
			}
		});
	});


	layui.use('laypage', function () {
		var laypage = layui.laypage;
		var totalCount=$("#ObtainNumber").val();
		var whichPage=$("#whichPage").val();
		var currentPage=$("#OcurrentPage").val();
		//执行一个laypage实例
		laypage.render({
			elem: 'Bpage3'
			, count: totalCount
			, limit: 20
			, curr: currentPage //获取起始页
			, first: '首页'
			, last: '尾页'
			, prev: '<em>←</em>'
			, next: '<em>→</em>'
			, skip: true
			, jump: function (obj, first) {
				if (!first) {
					window.location.href="/essay/essayreadbyuser.do?OcurrentPage="+obj.curr+"&whichPage="+whichPage;
				}
			}
		});
	});
})
